from itertools import combinations


def generate_covering_design(numbers):
    """
    生成最小的覆盖子集，确保每个5个数字的组合都能被至少一个6个数字的组合覆盖。
    """
    # 生成所有的5个数字组合
    all_combinations = set(combinations(numbers, 5))
    covering_design = []

    # 当还有未覆盖的组合时继续循环
    while all_combinations:
        best_subset = None
        max_coverage = 0

        # 寻找能够覆盖最多未覆盖组合的6个数字的组合
        for subset in combinations(numbers, 6):
            new_coverage = len(set(combinations(subset, 5)) & all_combinations)
            if new_coverage > max_coverage:
                max_coverage = new_coverage
                best_subset = subset

        if best_subset is not None:
            covering_design.append(best_subset)
            # 更新剩余需要覆盖的组合集合
            all_combinations -= set(combinations(best_subset, 5))
        else:
            break  # 如果没有新的组合可以增加覆盖，则退出循环

    return covering_design


if __name__ == "__main__":
    # 输入16个数字
    user_input = input("请输入16个数字，用空格分隔: ")
    numbers = list(map(int, user_input.split()))

    if len(numbers) != 16 or len(set(numbers)) != 16:
        print("输入无效！请提供16个不重复的数字。")
    else:
        # 生成覆盖设计
        cover = generate_covering_design(numbers)

        # 输出结果
        print("生成的覆盖设计包含以下数组:")
        for array in cover:
            print(array)

        # 输出数组的数量
        print(f"总共生成了 {len(cover)} 个数组")